package com.vm.util;

import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

import com.vm.common.Var;


public class UploadAndDownLoad {

	public static void copy(File src, File dst) {
        try {
           InputStream in = null ;
           OutputStream out = null ;
            try {   
            	in = new BufferedInputStream( new FileInputStream(src), Var.BUFFER_SIZE);
            	out = new BufferedOutputStream( new FileOutputStream(dst), Var.BUFFER_SIZE);
                byte [] buffer = new byte [Var.BUFFER_SIZE];
                while (in.read(buffer) > 0 ) {
                   out.write(buffer);
               }
           } finally {
                if ( null != in) {
                   in.close();
               }
                if ( null != out) {
                   out.close();
               }
           }
       } catch (Exception e) {
           e.printStackTrace();
       }
   } 
	/*
	 * 生成文件名称及扩展名
	 */
    public static String getExtention(String fileName) {
    	return UUID.randomUUID()+fileName.substring(fileName.lastIndexOf("."));
   } 
    /*
	 * 拿到文件�?
	 */
    public static String getFileName(String fileName) {
    	return fileName.substring(0, fileName.lastIndexOf("."));
   } 
    
    
//    public static void main(String[] args) {
//    	
//    	
//	}
}
